package com.sdtv.basemodule.config;

import android.app.Application;

import com.billy.android.loading.Gloading;
import com.sdtv.basemodule.rx.errorhandler.ResponseErrorListener;

/**
 * @ProjectName: MediunFusion
 * @Package: com.sdtv.basemodule.config
 * @ClassName: AppSetting
 * @Description: java类作用描述
 * @Author: 小郭同学
 * @CreateDate: 2019-06-20 11:15
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class AppSetting {

    //app设置
    private AppHttpSetting appHttpSetting;
    // 上下文环境
    private Application application;
    // 请求状态
    private Gloading.Adapter gloadingAdapter;
    private ResponseErrorListener errorListener;

    public AppSetting(Builder builder) {
        this.application = builder.mApplication;
        this.appHttpSetting = builder.appHttpSetting;
        this.gloadingAdapter = builder.adapter;
        this.errorListener = builder.errorListener;
    }

    public static Builder builder() {
        return new Builder();
    }

    public AppHttpSetting getAppHttpSetting() {
        return appHttpSetting;
    }

    public void setAppHttpSetting(AppHttpSetting appHttpSetting) {
        this.appHttpSetting = appHttpSetting;
    }

    public Application getApplication() {
        return application;
    }

    public void setApplication(Application application) {
        this.application = application;
    }

    public Gloading.Adapter getGloadingAdapter() {
        return gloadingAdapter;
    }

    public void setGloadingAdapter(Gloading.Adapter gloadingAdapter) {
        this.gloadingAdapter = gloadingAdapter;
    }

    public ResponseErrorListener getErrorListener() {
        return errorListener;
    }

    public void setErrorListener(ResponseErrorListener errorListener) {
        this.errorListener = errorListener;
    }

    // 构造者模式
    public static class Builder {
        Application mApplication;
        AppHttpSetting appHttpSetting;
        Gloading.Adapter adapter;
        ResponseErrorListener errorListener;

        public Builder with(Application application) {
            this.mApplication = application;
            return this;
        }

        public Builder setHttpSetting(AppHttpSetting httpSetting) {
            this.appHttpSetting = httpSetting;
            return this;
        }

        public Builder setErrorListener(ResponseErrorListener listener) {
            this.errorListener = listener;
            return this;
        }

        public Builder setGloadingAdapter(Gloading.Adapter adapter) {
            this.adapter = adapter;
            return this;
        }

        public AppSetting build() {
            if (null == mApplication) {
                throw new IllegalStateException("application is required");
            }
            if (null == appHttpSetting) {
                throw new IllegalStateException("AppHttpSetting is required");
            }
            if (null == errorListener) {
                throw new IllegalStateException("responseErrorListener is required");
            }
            return new AppSetting(this);
        }


    }

}
